package com.qiantu.phone.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.qiantu.api.entity.MemberBean;
import com.qiantu.api.entity.RoomBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.ui.activity.DeviceGroupListActivity;
import com.qiantu.phone.ui.activity.MemberManagerActivity;

import java.util.List;
import java.util.Map;

public class MemberManagerAdapter extends AppAdapter<Map<String,Object>> {

    public MemberManagerAdapter(Context context) {
        super(context);
    }
    @Override
    public MemberManagerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MemberManagerAdapter.ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvFloorName;
        private final RecyclerView roomRecyclerView;
        private final MemberDataAdapter memberDataAdapter;

        private ViewHolder() {
            super(R.layout.room_floor_select_item);
            tvFloorName = findViewById(R.id.tv_floor_name);
            roomRecyclerView = findViewById(R.id.room_recycler_view);
            roomRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
            memberDataAdapter = new MemberDataAdapter(getContext());
            roomRecyclerView.setAdapter(memberDataAdapter);
            memberDataAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(RecyclerView recyclerView, View itemView, int devicePosition) {
                    ((MemberManagerActivity)getContext()).gotoMemberInfoView(memberDataAdapter.getData().get(devicePosition));
                }
            } );
        }

        @Override
        public void onBindView(int position) {
            Map<String,Object> map = getItem(position);
            tvFloorName.setText(map.get("name").toString());
            memberDataAdapter.setData((List<MemberBean>) map.get("data"));
        }
    }

}
